/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cadastro;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.JTextField;
import principalcontrole.principal;
import utilitario.conexao;
//import utilitario.conexao;

/**
 *
 * @author marcos
 */
public class fornecedor extends javax.swing.JFrame {

    /**
     * Creates new form fornecedor
     */
    //criando um array liste
  private  ArrayList fornecedores;
  principal tela_principal;


  public fornecedor(principal tela_principal){
      this();
      this.tela_principal = tela_principal;

  }

    public fornecedor() {
        initComponents();

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        texto_titulo = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jPanel2 = new javax.swing.JPanel();
        lb_pesquisa = new javax.swing.JLabel();
        tf_pesquisa = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        lb_nome = new javax.swing.JLabel();
        tf_nome = new javax.swing.JTextField();
        lb_endereco = new javax.swing.JLabel();
        tf_end = new javax.swing.JTextField();
        cb_uf = new javax.swing.JComboBox();
        tf_cidade = new javax.swing.JTextField();
        lb_uf = new javax.swing.JLabel();
        lb_cidade = new javax.swing.JLabel();
        tf_cnpj = new javax.swing.JTextField();
        lb_cnpj = new javax.swing.JLabel();
        tf_cod = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        btn_salvar = new javax.swing.JButton();
        btn_excluir = new javax.swing.JButton();
        btn_novo = new javax.swing.JButton();
        btn_editar = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        tf_numero = new javax.swing.JTextField();
        lb_complemento = new javax.swing.JLabel();
        tf_comple = new javax.swing.JTextField();
        lb_cep = new javax.swing.JLabel();
        lb_fone = new javax.swing.JLabel();
        tf_cep = new javax.swing.JTextField();
        tf_fone = new javax.swing.JTextField();
        fundo = new javax.swing.JLabel();
        jTabbedPane1 = new javax.swing.JTabbedPane();

        setTitle("Cadastro Fornecedor");
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });
        getContentPane().setLayout(null);

        texto_titulo.setFont(new java.awt.Font("Cooper Black", 0, 36)); // NOI18N
        texto_titulo.setForeground(new java.awt.Color(0, 204, 51));
        texto_titulo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fornecedor.png"))); // NOI18N
        texto_titulo.setText("Casdastro Fornecedor");
        getContentPane().add(texto_titulo);
        texto_titulo.setBounds(230, 50, 460, 90);

        jPanel1.setOpaque(false);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Cod", "Nome", "End", "Numero", "Comple", "CEP", "Fone", "Cidade", "UF", "CNPJ"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jTable1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTable1KeyReleased(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel2.setOpaque(false);

        lb_pesquisa.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lb_pesquisa.setText("Pesquisa :");

        tf_pesquisa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_pesquisaActionPerformed(evt);
            }
        });
        tf_pesquisa.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tf_pesquisaKeyPressed(evt);
            }
        });

        jLabel1.setToolTipText("Precione ENTER para pesquisa.");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel2.setText("Codigo.:");

        lb_nome.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lb_nome.setText("Nome :");

        tf_nome.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tf_nomeKeyPressed(evt);
            }
        });

        lb_endereco.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lb_endereco.setText("Endereço :");

        tf_end.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_endActionPerformed(evt);
            }
        });
        tf_end.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tf_endKeyPressed(evt);
            }
        });

        cb_uf.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "GO", "AC", "SP", "RJ", "DF", "AP", "MT", "MS", "MG", "PA", "PB", "AM", "PR", "PS", "PE", "PI", "RS", "RO", "RR", "SC", "TO", "BA", "CE" }));
        cb_uf.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                cb_ufKeyPressed(evt);
            }
        });

        tf_cidade.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tf_cidadeKeyPressed(evt);
            }
        });

        lb_uf.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lb_uf.setText("UF :");

        lb_cidade.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lb_cidade.setText("Cidade :");

        tf_cnpj.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tf_cnpjKeyPressed(evt);
            }
        });

        lb_cnpj.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lb_cnpj.setText("CNPJ :");

        tf_cod.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_codActionPerformed(evt);
            }
        });
        tf_cod.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tf_codKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                tf_codKeyReleased(evt);
            }
        });

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pesquisa.png"))); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jButton1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jButton1KeyPressed(evt);
            }
        });

        btn_salvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/save.png"))); // NOI18N
        btn_salvar.setToolTipText("Salvar Fornecedor");
        btn_salvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_salvarActionPerformed(evt);
            }
        });

        btn_excluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/excluir.png"))); // NOI18N
        btn_excluir.setToolTipText("Excluir Fornecedor");
        btn_excluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_excluirActionPerformed(evt);
            }
        });

        btn_novo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/novo.png"))); // NOI18N
        btn_novo.setToolTipText("Novo Fornecedor");
        btn_novo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_novoActionPerformed(evt);
            }
        });

        btn_editar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/editar.png"))); // NOI18N
        btn_editar.setToolTipText("Editar Fornecedor");
        btn_editar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_editarActionPerformed(evt);
            }
        });

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/produto.png"))); // NOI18N
        jButton2.setToolTipText("Casdastar lista de produdo do fornecedor");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel3.setText("Numero :");

        tf_numero.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tf_numeroKeyPressed(evt);
            }
        });

        lb_complemento.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lb_complemento.setText("Complemento:");

        tf_comple.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tf_compleKeyPressed(evt);
            }
        });

        lb_cep.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lb_cep.setText("CEP:");

        lb_fone.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lb_fone.setText("Telefone :");

        tf_cep.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tf_cepKeyPressed(evt);
            }
        });

        tf_fone.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tf_foneKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                tf_foneKeyReleased(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(btn_novo)
                        .addGap(24, 24, 24)
                        .addComponent(lb_pesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tf_pesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, 380, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(tf_cod, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lb_nome, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(tf_nome, javax.swing.GroupLayout.PREFERRED_SIZE, 245, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(24, 24, 24)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lb_endereco)
                            .addComponent(tf_end, javax.swing.GroupLayout.PREFERRED_SIZE, 245, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(tf_numero, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lb_complemento)
                            .addComponent(tf_comple, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                                        .addGap(0, 24, Short.MAX_VALUE)
                                        .addComponent(btn_salvar)
                                        .addGap(18, 18, 18)
                                        .addComponent(btn_excluir))
                                    .addComponent(tf_cep))
                                .addGap(18, 18, 18))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(lb_cep)
                                .addGap(152, 152, 152)))
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(tf_fone, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addGap(8, 8, 8)
                                        .addComponent(btn_editar)))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(tf_cidade, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jButton2)))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(lb_fone)
                                .addGap(44, 44, 44)
                                .addComponent(lb_cidade)))
                        .addGap(24, 24, 24)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                                .addComponent(lb_uf)
                                .addGap(34, 34, 34))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(cb_uf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(14, 14, 14)))
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lb_cnpj)
                            .addComponent(tf_cnpj, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(8, 8, 8)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(tf_pesquisa)
                            .addComponent(lb_pesquisa, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(btn_novo, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tf_cod, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(lb_nome)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tf_nome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(lb_endereco)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tf_end, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tf_numero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lb_complemento)
                    .addComponent(lb_cep)
                    .addComponent(lb_fone)
                    .addComponent(lb_cidade)
                    .addComponent(lb_uf)
                    .addComponent(lb_cnpj))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tf_comple, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tf_cep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tf_fone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tf_cidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cb_uf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tf_cnpj, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 23, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(btn_salvar)
                        .addGap(21, 21, 21))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btn_excluir)
                            .addComponent(btn_editar)
                            .addComponent(jButton2))
                        .addContainerGap())))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE)
                .addGap(15, 15, 15))
        );

        getContentPane().add(jPanel1);
        jPanel1.setBounds(30, 170, 740, 420);

        fundo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fundo_fornecedor.png"))); // NOI18N
        getContentPane().add(fundo);
        fundo.setBounds(0, -20, 800, 640);
        getContentPane().add(jTabbedPane1);
        jTabbedPane1.setBounds(0, 0, 5, 5);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-817)/2, (screenSize.height-639)/2, 817, 639);
    }// </editor-fold>//GEN-END:initComponents

    private void btn_novoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_novoActionPerformed
        // TODO add your handling code here:

      //chamando o metodo para limpar campo
      limpa_campo();

    }//GEN-LAST:event_btn_novoActionPerformed

    private void limpa_campo()
    {
        //limpando os campos
        tf_cod.setText("");
        tf_nome.setText("");
        tf_cidade.setText("");
        tf_end.setText("");
        tf_numero.setText("");
        tf_comple.setText("");
        tf_cep.setText("");
        tf_fone.setText("");
        cb_uf.setSelectedItem("GO");
        tf_numero.setText("");
        tf_comple.setText("");
        tf_cep.setText("");
        tf_fone.setText("");

    }
    private void btn_salvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_salvarActionPerformed
        // TODO add your handling code here:

        //criando uma tabela e selecionando todos campo da tabela
        DefaultTableModel dtm_fornecedor = (DefaultTableModel) jTable1.getModel();

        //salvando os campos lido no tf_field na tabela
        dtm_fornecedor.addRow(new Object[]{tf_cod.getText(),tf_nome.getText(),tf_end.getText(),tf_numero.getText(),tf_comple.getText(),tf_cep.getText(),tf_fone.getText(),tf_cidade.getText(),cb_uf.getSelectedItem(),tf_cnpj.getText()});

        // salvando no array list
        fornecedores.add(new cad_fornecedor(tf_cod.getText(),tf_nome.getText(),tf_end.getText(),tf_numero.getText(),tf_comple.getText(),tf_cep.getText(),tf_fone.getText(),tf_cidade.getText(),cb_uf.getSelectedItem().toString(),tf_cnpj.getText()));
        // granvando no arquivo
        grava_no_arquivo();


    }//GEN-LAST:event_btn_salvarActionPerformed

    //funçao do btn_excluir
    private void btn_excluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_excluirActionPerformed
        // TODO add your handling code here:

        //pegando o valor de return da linha selecionada da minha tabela
        int linhaSelecionada = jTable1.getSelectedRow();

        //se linha nao for selecionada o return dela sera -1 linha, caso contrario ela entra no if
        if(jTable1.getSelectedRow()!=-1){

            //criando uma tabela e selecionado todos campo da tabela
            DefaultTableModel dtm_fornecedor = (DefaultTableModel) jTable1.getModel();

           //removendo a linha selecionada da tabela
           dtm_fornecedor.removeRow(jTable1.getSelectedRow());

           //removendo a linha selecionada do arraylist
           fornecedores.remove(linhaSelecionada);

           //depois de remover eu gravo no arquivo, chamando o metodo
           grava_no_arquivo();

           //quantoRegistro recebe quantidade de linha tem minha tabela
            int quantoRegistro = jTable1.getRowCount();

            //condiçao de se quantoRegistro for maior do que a linha selecionada
            if(quantoRegistro > linhaSelecionada)
            {

            jTable1.setRowSelectionInterval(linhaSelecionada,linhaSelecionada);

            setField();
            }
            else if(jTable1.getRowCount() > 0)
            {

                 jTable1.setRowSelectionInterval(linhaSelecionada-1,linhaSelecionada-1);
                 setField();
            }
            else{
            limpa_campo();

            }



        }
        else
         JOptionPane.showMessageDialog(null,"Por favor selecione uma linha!");
    }//GEN-LAST:event_btn_excluirActionPerformed

    private void tf_pesquisaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tf_pesquisaActionPerformed
        // TODO add your handling code here:
        String nome_pesq = tf_pesquisa.getText();
        boolean ver = false;

        if(nome_pesq.length()>0){

             for(int i=0;i<jTable1.getRowCount();i++)
            {
                if(nome_pesq.equals(jTable1.getValueAt(i,1)))
                {
                 tf_cod.setText(jTable1.getValueAt(i,0).toString());
                 tf_nome.setText(jTable1.getValueAt(i,1).toString());
                 tf_end.setText(jTable1.getValueAt(i,2).toString());
                 tf_numero.setText(jTable1.getValueAt(i,3).toString());
                 tf_comple.setText(jTable1.getValueAt(i,4).toString());
                 tf_cep.setText(jTable1.getValueAt(i,5).toString());
                 tf_fone.setText(jTable1.getValueAt(i,6).toString());
                 tf_cidade.setText(jTable1.getValueAt(i,7).toString());
                 cb_uf.setSelectedItem(jTable1.getValueAt(i,8).toString());
                 tf_cnpj.setText(jTable1.getValueAt(i,9).toString());

                  ver= true;
                  break;
                }


           }


        }
        if(ver == false){
        JOptionPane.showMessageDialog(null,"Nao encotrou nada!");
        tf_pesquisa.setText("");
        }

    }//GEN-LAST:event_tf_pesquisaActionPerformed

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
        // TODO add your handling code here:

        setField();

    }//GEN-LAST:event_jTable1MouseClicked

    private void setField(){
     int linha = jTable1.getSelectedRow();

          tf_cod.setText(jTable1.getValueAt(linha,0).toString());
                 tf_nome.setText(jTable1.getValueAt(linha,1).toString());
                 tf_end.setText(jTable1.getValueAt(linha,2).toString());
                 tf_numero.setText(jTable1.getValueAt(linha,3).toString());
                 tf_comple.setText(jTable1.getValueAt(linha,4).toString());
                 tf_cep.setText(jTable1.getValueAt(linha,5).toString());
                 tf_fone.setText(jTable1.getValueAt(linha,6).toString());
                 tf_cidade.setText(jTable1.getValueAt(linha,7).toString());
                 cb_uf.setSelectedItem(jTable1.getValueAt(linha,8).toString());
                 tf_cnpj.setText(jTable1.getValueAt(linha,9).toString());



    }


    private void jTable1KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTable1KeyReleased
        // TODO add your handling code here:
             setField();
    }//GEN-LAST:event_jTable1KeyReleased

    private void tf_endActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tf_endActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tf_endActionPerformed

    //metedo para gravar no arquvo
    private void grava_no_arquivo()
    {
            int quantos = jTable1.getRowCount();

        fornecedores.clear();

        for(int i =0;i<quantos;i++)
        {

        fornecedores.add(new cad_fornecedor(jTable1.getValueAt(i, 0).toString(),
                jTable1.getValueAt(i, 1).toString(),
                jTable1.getValueAt(i, 2).toString(),
                jTable1.getValueAt(i, 3).toString(),
                 jTable1.getValueAt(i, 4).toString(),
                 jTable1.getValueAt(i, 5).toString(),
                 jTable1.getValueAt(i, 6).toString(),
                jTable1.getValueAt(i, 7).toString(),
                 jTable1.getValueAt(i, 8).toString(),
                jTable1.getValueAt(i, 9).toString()));


        }
       try{
         ObjectOutputStream arquivo_gravar = new ObjectOutputStream(new FileOutputStream(new File("docs/cad_forn.bat")));
         arquivo_gravar.writeObject(fornecedores);

        }
        catch(Exception erro){

            JOptionPane.showMessageDialog(null,"ERRO AO GRAVAR!!"+erro);
        }


    }

    private void btn_editarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_editarActionPerformed
        // TODO add your handling code here:

        //editar
        jTable1.setValueAt(tf_cod.getText(),jTable1.getSelectedRow(), 0);
        jTable1.setValueAt(tf_nome.getText(),jTable1.getSelectedRow(), 1);
        jTable1.setValueAt(tf_end.getText(),jTable1.getSelectedRow(), 2);
        jTable1.setValueAt(tf_numero.getText(),jTable1.getSelectedRow(), 3);
        jTable1.setValueAt(tf_comple.getText(),jTable1.getSelectedRow(), 4);
        jTable1.setValueAt(tf_cep.getText(),jTable1.getSelectedRow(), 5);
        jTable1.setValueAt(tf_fone.getText(),jTable1.getSelectedRow(), 6);
        jTable1.setValueAt(tf_cidade.getText(),jTable1.getSelectedRow(), 7);
        jTable1.setValueAt(cb_uf.getSelectedItem(),jTable1.getSelectedRow(), 8);
        jTable1.setValueAt(tf_cnpj.getText(),jTable1.getSelectedRow(), 9);

        grava_no_arquivo();

    }//GEN-LAST:event_btn_editarActionPerformed

    private void tf_codActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tf_codActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tf_codActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:

        new cad_prod_forn(tf_nome.getText()).setVisible(true);


    }//GEN-LAST:event_jButton2ActionPerformed

    private void tf_codKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tf_codKeyReleased
        // TODO add your handling code here:

        tf_cod.setText(tf_cod.getText().replaceAll("[^0-9]", ""));
    }//GEN-LAST:event_tf_codKeyReleased

    private void tf_codKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tf_codKeyPressed
        // TODO add your handling code here:
        if(evt.getKeyCode() == 10){

            tf_nome.requestFocus();

        }
    }//GEN-LAST:event_tf_codKeyPressed

    private void tf_nomeKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tf_nomeKeyPressed
        // TODO add your handling code here:
        if(evt.getKeyCode() == 10){

            tf_end.requestFocus();

        }
    }//GEN-LAST:event_tf_nomeKeyPressed

    private void tf_endKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tf_endKeyPressed
        // TODO add your handling code here:
           if(evt.getKeyCode() == 10){

            tf_numero.requestFocus();

        }
    }//GEN-LAST:event_tf_endKeyPressed

    private void tf_numeroKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tf_numeroKeyPressed
        // TODO add your handling code here:
           if(evt.getKeyCode() == 10){

            tf_comple.requestFocus();

        }
    }//GEN-LAST:event_tf_numeroKeyPressed

    private void tf_compleKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tf_compleKeyPressed
        // TODO add your handling code here:
           if(evt.getKeyCode() == 10){

            tf_cep.requestFocus();

        }
    }//GEN-LAST:event_tf_compleKeyPressed

    private void tf_cepKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tf_cepKeyPressed
        // TODO add your handling code here:
           if(evt.getKeyCode() == 10){

            tf_fone.requestFocus();

        }
    }//GEN-LAST:event_tf_cepKeyPressed

    private void tf_foneKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tf_foneKeyPressed
        // TODO add your handling code here:
           if(evt.getKeyCode() == 10){

            tf_cidade.requestFocus();

        }
    }//GEN-LAST:event_tf_foneKeyPressed

    private void tf_cidadeKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tf_cidadeKeyPressed
        // TODO add your handling code here:
           if(evt.getKeyCode() == 10){

            cb_uf.requestFocus();

        }
    }//GEN-LAST:event_tf_cidadeKeyPressed

    private void cb_ufKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cb_ufKeyPressed
        // TODO add your handling code here:
           if(evt.getKeyCode() == 10){

            tf_cnpj.requestFocus();

        }
    }//GEN-LAST:event_cb_ufKeyPressed

    private void tf_cnpjKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tf_cnpjKeyPressed
        // TODO add your handling code here:
           if(evt.getKeyCode() == 10){

            btn_salvar.requestFocus();

        }
    }//GEN-LAST:event_tf_cnpjKeyPressed

    private void tf_pesquisaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tf_pesquisaKeyPressed
        // TODO add your handling code here:
    }//GEN-LAST:event_tf_pesquisaKeyPressed

    private void tf_foneKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tf_foneKeyReleased
        // TODO add your handling code here:
        tf_fone.setText(tf_fone.getText().replaceAll("[^0-9]", ""));
    }//GEN-LAST:event_tf_foneKeyReleased

    private void jButton1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jButton1KeyPressed
        // TODO add your handling code here:

    }//GEN-LAST:event_jButton1KeyPressed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        // TODO add your handling code here:
        tela_principal.setEnabled(true);

        Thread t = new Thread();

        t.start();
    }//GEN-LAST:event_formWindowClosed

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        // TODO add your handling code here:

        carrega_do_arquivo();



        //definindo os tamanho dos item da minha tabela
        jTable1.getColumnModel().getColumn(0).setPreferredWidth(50);//codigo
        jTable1.getColumnModel().getColumn(1).setPreferredWidth(250);//nome
        jTable1.getColumnModel().getColumn(2).setPreferredWidth(200);//endereço
        jTable1.getColumnModel().getColumn(3).setPreferredWidth(50);//numeto
        jTable1.getColumnModel().getColumn(4).setPreferredWidth(60);//complemento
        jTable1.getColumnModel().getColumn(5).setPreferredWidth(80);//cep
        jTable1.getColumnModel().getColumn(6).setPreferredWidth(40);// telefone
        jTable1.getColumnModel().getColumn(7).setPreferredWidth(100);//cidade
        jTable1.getColumnModel().getColumn(8).setPreferredWidth(40);//uf
        jTable1.getColumnModel().getColumn(9).setPreferredWidth(150);//cnpj

    }//GEN-LAST:event_formWindowOpened
public void carrega_do_arquivo()
{


   DefaultTableModel dmt =  (DefaultTableModel) jTable1.getModel();
       dmt.setNumRows(0);


     cad_fornecedor obj_fornecedor;

         try{
         ObjectInputStream arquivo_ler = new ObjectInputStream(new FileInputStream(new File("docs/cad_forn.bat")));
         fornecedores = (ArrayList) arquivo_ler.readObject();

        }
         catch(ClassNotFoundException erro){
             JOptionPane.showMessageDialog(null,"a classe nao foi encontrada "+erro);

         }
         catch(FileNotFoundException erro)
         {
         JOptionPane.showMessageDialog(null,"o arquivo nao foi encotrado"+erro);
         }
        catch(Exception erro){

            JOptionPane.showMessageDialog(null,"ERRO AO GRAVAR!!"+erro);
        }

         Object campos[] = new Object[10];

         Iterator iterator;
        iterator = fornecedores.iterator();

        while(iterator.hasNext()) //ir para o prximo elemento
        {
            obj_fornecedor = (cad_fornecedor) iterator.next();
            campos[0] = obj_fornecedor.getCodigo();
            campos[1] = obj_fornecedor.getNome();
            campos[2] = obj_fornecedor.getEndereco();
            campos[3] = obj_fornecedor.getNumero();
            campos[4] = obj_fornecedor.getComplemento();
            campos[5] = obj_fornecedor.getCep();
            campos[6] = obj_fornecedor.getTelefone();
            campos[7] = obj_fornecedor.getCidade();
            campos[8] = obj_fornecedor.getUf();
            campos[9] = obj_fornecedor.getCnpj();

           dmt.addRow(campos);
        }

         if(jTable1.getRowCount() > 0){

             jTable1.setRowSelectionInterval(0, 0);
             setField();



        }


}
public JTextField getNome(){
return this.tf_nome;
}
public String getNOME(){

    String str = tf_nome.getText();
      return str;



}


    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(fornecedor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(fornecedor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(fornecedor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(fornecedor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new fornecedor().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_editar;
    private javax.swing.JButton btn_excluir;
    private javax.swing.JButton btn_novo;
    private javax.swing.JButton btn_salvar;
    private javax.swing.JComboBox cb_uf;
    private javax.swing.JLabel fundo;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JLabel lb_cep;
    private javax.swing.JLabel lb_cidade;
    private javax.swing.JLabel lb_cnpj;
    private javax.swing.JLabel lb_complemento;
    private javax.swing.JLabel lb_endereco;
    private javax.swing.JLabel lb_fone;
    private javax.swing.JLabel lb_nome;
    private javax.swing.JLabel lb_pesquisa;
    private javax.swing.JLabel lb_uf;
    private javax.swing.JLabel texto_titulo;
    private javax.swing.JTextField tf_cep;
    private javax.swing.JTextField tf_cidade;
    private javax.swing.JTextField tf_cnpj;
    private javax.swing.JTextField tf_cod;
    private javax.swing.JTextField tf_comple;
    private javax.swing.JTextField tf_end;
    private javax.swing.JTextField tf_fone;
    private javax.swing.JTextField tf_nome;
    private javax.swing.JTextField tf_numero;
    private javax.swing.JTextField tf_pesquisa;
    // End of variables declaration//GEN-END:variables
}
